<?php

use Jialeo\LaravelSchemaExtend\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitResale extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 转售记录
        Schema::create('resale_records', function (Blueprint $table) {
            $table->comment = '转售记录';
            
            $table->increments('id');
            $table->uuid('uuid')->index();

            $table->integer('user_id')->index()->comment('发起的用户id'); // 用户id
            $table->integer('pending_user_id')->nullable()->comment('正在支付的用户id'); // 用户id
            $table->integer('complete_user_id')->nullable()->comment('最终支付的用户id'); // 用户id

            $table->char('resale_type', 20)->index()->comment('转售类型 package_sku  和 package');
            $table->integer('package_id')->index()->nullable()->comment('仓库sku id'); // 用户id
            $table->integer('package_sku_id')->index()->nullable()->comment('package id'); // 用户id

            $table->integer('money_price')->unsigned()->nullable()->comment('人民币价格');
            $table->integer('score_price')->unsigned()->nullable()->comment('人民币价格');

            $table->integer('pending_order_id')->unsigned()->nullable()->comment('正在支付的订单id'); 
            $table->integer('complete_order_id')->unsigned()->nullable()->comment('支付订单id'); 

            $table->timestamp('pending_at')->nullable()->comment('开始占用的时间'); 
            $table->timestamp('complete_at')->nullable()->comment('交易完成时间'); 
            $table->timestamp('closed_at')->nullable()->comment('关闭时间'); 

            $table->boolean('is_public')->default(0)->index()->comment('是否公开在公共挂售区'); 

            $table->string('limit_phone', 20)->nullable()->comment('要设置限制仅某手机号用户购买');

            $table->tinyInteger('status')->unsigned()->default(1)->index()->comment('状态 1为进行中 2为已成交  3为已失效  4为用户取消  5为交易中');

            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('resale_records');
    }
}
